/// <reference path="../../../../shared/references.scss" />
//@import 'summernote-icons.scss'; // Obsolete, we now use inline SVG icons for the missing ones

$note-border-color: $input-border-color;
$note-bg: #8080801d;

$img-margin-left: 10px;
$img-margin-right: 10px;


// Wrapper & Preview
// ------------------------------------------

.note-editor-preview {
    border: 1px solid $input-border-color;
    min-height: 100px;
    max-height: 350px;
    overflow-x: hidden;
    overflow-y: auto;
    padding: $input-padding-y $input-padding-x;
    border-radius: $input-border-radius;
    cursor: default;

    &.empty {
        min-height: initial;
        //color: $text-muted;
    }
}

// Dropzone
// ------------------------------------------

.note-dropzone {
    position: absolute;
    display: none;
    z-index: 100;
    color: lightskyblue;
    background-color: #fff;
    opacity: 0.95;
    border-radius: $input-border-radius;

    .note-dropzone-message {
        display: table-cell;
        vertical-align: middle;
        text-align: center;
        font-size: 28px;
        font-weight: 600;
    }

    &.hover {
        color: var(--primary);
    }

    .note-editor.dragover & {
        display: table;
    }
}


// Editor
// ------------------------------------------

.note-editor {
    position: relative;
    border: 1px solid $note-border-color;
    @include border-top-radius($input-border-radius);
    @include border-bottom-radius($input-border-radius);
    --note-sticky-toolbar-zindex: #{$zindex-sticky - 1};

    &:focus-within,
    &:focus,
    &.focus {
        z-index: $zindex-sticky - 1;
        border-color: $input-focus-border-color;
    }

    .note-placeholder {
        padding: 10px;
    }

    &.note-airframe {
        border-width: 0;
    }

    .note-editing-area {
        flex-grow: 1;
    }

    .note-editable,
    .note-codable,
    .CodeMirror {
        height: 100%;
    }

    .CodeMirror {
        border-width: 0;
    }
}


// Editing area
// ------------------------------------------

.note-editing-area {
    position: relative;
    overflow: hidden;
    background: #f5f5f5;
    background: var(--gray-400);
}


// Editable
// ------------------------------------------

.note-editable {
    outline: none;
    padding: 10px;
    overflow: auto;
    word-wrap: break-word;
    height: auto;
    background: #fff;
    display: block;
    margin-inline: auto;
    will-change: width;
    box-shadow: 0px 0px 5px 1px rgba(50,50,93, 0.15), 0 0 1rem 0px rgba($black, 0.1);
    // Reset
    font-weight: normal;
    font-style: normal;
    text-decoration: none;
    --zoom: 1;
    zoom: var(--zoom);

    a {
        text-decoration: underline;
    }

    .note-airframe & {
        padding: 0;
    }

    &[contenteditable="false"] {
        background-color: $note-bg;
    }

    sup {
        vertical-align: super;
    }

    sub {
        vertical-align: sub;
    }

    img.note-float-left {
        margin-right: $img-margin-right;
    }

    img.note-float-right {
        margin-left: $img-margin-left;
    }
    // // Alignment does not work with or without sequences
    // ul li,
    // ol li {
    //   list-style-position: inside;
    // }

    table:not(.table-bordered):not([border]),
    table:not(.table-bordered)[border='0'] {
        border-collapse: collapse;

        td,
        th {
            border: 1px dashed #bbb;
        }
    }
}


// Codeview
// ------------------------------------------

.note-editor.codeview {
    .note-editable,
    .note-statusbar-content {
        display: none;
    }

    &.fullscreen .note-statusbar {
        display: none;
    }

    .note-codable {
        display: block;
    }
}


// Codable
// ------------------------------------------

.note-codable {
    display: none;
    width: 100%;
    padding: 10px;
    border: none;
    box-shadow: none;
    font-family: Menlo, Monaco, monospace, sans-serif;
    font-size: 14px;
    color: #ccc;
    background-color: #222;
    resize: none;
    outline: none;
    box-sizing: border-box;
    border-radius: 0;
    margin-bottom: 0;
}


// Fullscreen
// ------------------------------------------

.note-editor.fullscreen {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 100% !important;
    height: 100% !important;
    min-height: initial !important;
    max-height: initial !important;
    border-radius: 0 !important;
    border-color: $note-border-color !important;
    z-index: $zindex-tooltip !important;

    > .note-toolbar {
        position: relative !important;
        z-index: auto !important;
        top: 0 !important;
        width: 100% !important;
    }

    .note-editing-area {
        flex-grow: 1;
    }

    .note-editable,
    .note-codable,
    .CodeMirror {
        height: 100%;
    }

    .note-resizebar {
        cursor: default;
        pointer-events: none;

        > .note-icon-bar {
            display: none;
        }
    }
}

.note-fullscreen-body {
    overflow: hidden !important;
}


// Notifications
// ------------------------------------------

.note-status-output {
    display: block;
    width: 100%;
    font-size: 13px;
    line-height: 1.2;
    border: 0;
    border-top: 1px solid $input-border-color;
    padding: 4px 8px;
    font-weight: 600;

    &:empty {
        height: 0;
        padding: 0;
        border-top-width: 0;
    }
}


// Statusbar
// ------------------------------------------

.note-statusbar {
    position: relative;
    background-color: $note-bg;
    border-top: 1px solid rgba($black, 0.15);
}

.note-statusbar-content {
    position: relative;
    display: flex;
    justify-content: space-between;
    flex-wrap: nowrap;
    font-size: 13px;
    padding: 8px 8px 0 8px;
    line-height: 1;
}

.note-path-item {
    display: inline-block;
    cursor: pointer;

    &:hover {
        color: var(--gray-650);
    }
}

.note-path-item-divider {
    cursor: default;
}

.note-tag-glimpse {
    position: absolute;
    pointer-events: none;
    z-index: $zindex-tooltip - 1;
    background-color: rgba(var(--primary-rgb), 0.2);
}

.note-resizebar {
    padding-top: 1px;
    height: 9px;
    width: 100%;
    cursor: row-resize;

    > .note-icon-bar {
        width: 20px;
        margin: 1px auto;
        border-top: 1px solid rgba($black, 0.2);
    }
}

.note-zoomer {
    margin-top: -4px;
    margin-bottom: -4px;
}

.btn.note-zoom-action {
    --btn-height: 20px;
    --btn-active-shadow: none;
    box-shadow: none !important;
}

.note-zoom-value {
    width: 36px;
    text-align: end;
    user-select: none;
}

.note-statusbar.locked {
    > .note-statusbar-content {
        display: none;
    }

    > .note-resizebar {
        cursor: default;

        > .note-icon-bar {
            display: none;
        }
    }
}


// Color Palette
// ------------------------------------------

.note-color > .dropdown-toggle {
    min-width: initial;
}

.note-palette {
    display: flex;
    flex-direction: column;
    row-gap: 8px;
    margin: 0;
}

.note-palette-title {
    font-size: 13px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 2px;
}

.note-color-reset,
.note-color-select {
    --btn-height: 24px !important;
}

.note-color-select-btn {
    display: none;
}

.note-holder-custom .note-color-btn {
    border: 1px solid var(--gray-200) !important;
}

.note-color-palette {
    --note-color-gap: 4px;
    --note-color-size: 18px;
    line-height: 1;
    display: flex;
    flex-flow: column;
    row-gap: var(--note-color-gap);

    .note-color-row {
        display: flex;
        column-gap: var(--note-color-gap);
    }

    .note-color-btn {
        width: var(--note-color-size);
        height: var(--note-color-size);
        padding: 0;
        margin: 0;
        border: 0;
        border-radius: 0;
        transition: transform 0.12s;
    }

    .note-color-btn:hover:not(:active) {
        transform: scale(1.2);
    }
}


// Placeholder & Selection
// ------------------------------------------

.note-placeholder {
    position: absolute;
    display: none;
    color: var(--gray-600);
}

.note-selection {
    background-color: var(--primary-bg-subtle);
    color: var(--body-color);
}


// Modal Dialog
// ------------------------------------------

.note-modal {
    .form-group {
        margin-inline: 0;
        margin-bottom: 0.5rem;

        &:last-child {
            margin-bottom: 0;
        }
    }

    .note-form-label {
        margin-bottom: 0.25rem;
    }

    .note-modal-form {
        margin: 0;
    }

    .modal-footer > .btn {
        min-width: 80px;

        > svg {
            height: 16px;
            color: currentColor;
            fill: currentColor;
        }
    }
}


// Handle / Control selection
// ------------------------------------------

.note-control-selection {
    position: absolute;
    display: none;
    border: 1px solid #000;
    z-index: 1;

    & > div {
        position: absolute;
    }
}

.note-control-selection-bg {
    width: 100%;
    height: 100%;
    background-color: #000;
    opacity: 0.3;
}

.note-control-handle {
    width: 7px;
    height: 7px;
    border: 1px solid #000;
}

.note-control-holder {
    @extend .note-control-handle;
}

.note-control-sizing {
    @extend .note-control-handle;
    background-color: #000;
}

.note-control-nw {
    top: -5px;
    left: -5px;
    border-right: none;
    border-bottom: none;
}

.note-control-ne {
    top: -5px;
    right: -5px;
    border-bottom: none;
    border-left: none;
}

.note-control-sw {
    bottom: -5px;
    left: -5px;
    border-top: none;
    border-right: none;
}

.note-control-se {
    right: -5px;
    bottom: -5px;
    cursor: se-resize;
}

.note-control-se.note-control-holder {
    cursor: default;
    border-top: none;
    border-left: none;
}

.note-control-selection-info {
    right: 0;
    bottom: 0;
    padding: 5px;
    margin: 5px;
    color: #fff;
    background-color: #000;
    font-size: 12px;
    opacity: 0.7;
    border-radius: 5px;
}


// Hint popover
// ------------------------------------------

.note-hint-popover {
    min-width: 100px;
    padding: 2px;

    .popover-content {
        padding: 3px;
        max-height: 150px;
        overflow: auto;
    }
}

.note-hint-group {
    .note-hint-item {
        display: block !important;
        padding: 3px;

        &.active,
        &:hover {
            display: block;
            clear: both;
            font-weight: 400;
            line-height: 1.4;
            color: white;
            white-space: nowrap;
            text-decoration: none;
            background-color: #428bca;
            outline: 0;
            cursor: pointer;
        }
    }
}


// Dropdown menu for toolbar and popover
// -------------------------------------

.note-dropdown-menu {
    > .dropdown-item > * {
        // Overwrite all reboot margins in Summernote dropdown items
        margin-bottom: 0;
    }
    // dropdown-menu right position
    // http://forrst.com/posts/Bootstrap_right_positioned_dropdown-2KB
    &.right {
        right: 0;
        left: auto;

        &:before {
            right: 9px;
            left: auto !important;
        }

        &:after {
            right: 10px;
            left: auto !important;
        }
    }
    // dropdown-menu for selectbox
    &.note-check {
        min-width: initial;

        > .dropdown-item {
            justify-content: space-between;

            > i {
                color: var(--warning);
                visibility: hidden;
                order: 2;
                margin-inline: 10px -4px !important;
            }

            &.checked {
                font-weight: 600;

                > i {
                    visibility: visible;
                }
            }
        }
    }
}


// Tools
// ------------------------------------------

.note-toolbar-wrapper {
    position: relative;
}

.note-popover.popover {
    display: none;
    max-width: none;
    border-color: var(--gray-300);
    z-index: $zindex-tooltip + 1;

    .arrow {
        //left: 20px !important;
        &:before {
            border-bottom-color: var(--gray-300);
        }
    }
}

.note-toolbar {
    $btn-height: calc((#{$btn-line-height-sm} * 1em) + (#{$btn-padding-y-sm} * 2) + (#{$btn-border-width} * 2));
    $btn-height: 32.56px;

    --note-btn-active-border-color: rgba(var(--primary-rgb), 0.3);
    --note-toolbar-gap: 5px;
    --note-toolbar-rowheight: calc(#{$btn-height} + (var(--note-toolbar-gap) * 2));
    margin: 0;
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: center;
    padding: var(--note-toolbar-gap);
    column-gap: var(--note-toolbar-gap);
    row-gap: calc(var(--note-toolbar-gap) * 2);

    &.note-toolbar-main {
        // Main toolbar
        position: relative;
        flex-wrap: wrap;
        border-bottom-width: 0;
        background-image: linear-gradient(rgba(0,0,0, 0.1) 1px, transparent 1px);
        background-size: 100% var(--note-toolbar-rowheight);
        background-position: 0 -1px;
        background-color: var(--gray-100);
        @include border-top-radius($input-border-radius);

        > .note-toolgroup:last-of-type {
            margin-inline-start: auto;
        }
    }

    &.note-toolbar-sticky {
        // Main toolbar
        position: sticky;
        z-index: var(--note-sticky-toolbar-zindex);
    }

    &:not(.dropdown-menu) {
        display: flex;
    }

    &.dropdown-menu.show {
        display: flex;
    }

    .scrollable-menu {
        height: auto;
        max-height: 400px;
        min-width: 280px;
        overflow-x: hidden;
    }
}

.note-toolgroup {
    display: inline-flex;
    position: relative;
    column-gap: 2px;
    border: 0 solid rgba($black, 0.12);
    border-inline-end-width: 1px;
    padding-inline-end: 5px;

    &:last-of-type {
        border-inline-end-width: 0;
        padding-inline-end: 0;
    }
}

.note-btn {
    @include button-flat();
    min-width: 32px;
    // Change color hover/active/pressed styling
    --btn-padding-x: 6px;
    --btn-active-bg: rgba(var(--primary-bg-subtle-rgb), 0.75);
    --btn-active-color: var(--primary-text-emphasis);
    --btn-active-border-color: transparent;
    --btn-active-shadow: none;

    > i,
    > svg {
        font-size: 16px !important;
        fill: currentColor;
    }

    > svg {
        height: 16px;
    }

    &:active,
    .note-btn-group.show > & {
        --btn-active-bg: var(--primary-bg-subtle) !important;
        --btn-active-border-color: var(--note-btn-active-border-color) !important;
    }
}

.note-duotone-primary,
.note-duotone-secondary {
    color: var(--primary);
}

.note-duotone-secondary {
    opacity: 0.4;
}

.btn-group-split {
    // Split dropdown buttons, e.g. "Color"
    outline: 1px solid transparent;
    outline-offset: -1px;
    border-radius: $btn-border-radius-sm;

    &:hover,
    &.show {
        outline-color: var(--note-btn-active-border-color);
    }
}


// Para style dropdown
// -------------------------------------

.dropdown-style.dropdown-menu {

    blockquote,
    pre {
        margin: 0;
    }

    pre {
        padding-block: 5px;
        width: 100%;
    }

    h1,
    h2,
    h3,
    h4,
    h5,
    h6,
    p {
        margin: 0;
        padding: 0;
    }
}


// Color dropdowns
// -------------------------------------

.note-color > .dropdown-toggle {
    padding-inline: 6px;
}

.note-color-all > .note-dropdown-menu {
    min-width: auto;
    padding: 12px;
    column-gap: 16px;

    &.show {
        display: flex;
    }
}


// Table dropdown
// -------------------------------------

.note-table.dropdown-menu {
    min-width: 0;
    padding: 5px;
}

.note-dimension-picker {
    font-size: 18px;
}

.note-dimension-picker-mousecatcher {
    position: absolute !important;
    z-index: 3;
    width: 10em;
    height: 10em;
    cursor: pointer;
}

.note-dimension-picker-unhighlighted {
    position: relative !important;
    z-index: 1;
    width: 5em;
    height: 5em;
    background: url("") repeat;
}

.note-dimension-picker-highlighted {
    position: absolute !important;
    z-index: 2;
    width: 1em;
    height: 1em;
    background: url("") repeat;
}

.note-current-color-button {
    --btn-padding-x: 4px;
    --btn-padding-y: 4px;

    > .note-recent-color {
        display: inline-block;
        outline: 1px solid rgba($black, 0.1);
        outline-offset: -1px;
        padding: 2px;
        border-radius: 3px;
    }
}

.note-video-clip {
    max-width: 100%;
}

// Emojis
// ------------------------------------------

.note-emoji-popover {
    --note-emoji-size: 40px;
    --note-emoji-gap: 1px;
    --note-emoji-cols: 10;
    --note-emoji-padding: 0.5rem;

    > .popover-content-emoji {
        display: flex;
        flex-flow: column;
        overflow: hidden;
        height: 348px;
        width: calc(var(--note-emoji-size) * var(--note-emoji-cols) + (var(--note-emoji-gap) * var(--note-emoji-cols)) + (var(--note-emoji-padding) * 2) + 13px);
    }
}

.note-emoji-searchbox {
    padding-inline: var(--note-emoji-padding);
}

.note-emoji-list {
    gap: var(--note-emoji-gap);
    overflow-y: auto;
    scrollbar-gutter: stable;
    margin: var(--note-emoji-padding);
    margin-inline-end: 0;
    padding-inline-end: var(--note-emoji-padding);
}

.nav.nav-emoji {
    justify-content: space-around;
    flex-wrap: nowrap;

    > .nav-link {
        &:not(.active) {
            filter: grayscale(1);
            opacity: 0.65;
        }
    }
}

.btn.note-emoji {
    font-size: 24px;
    font-weight: var(--font-weight-normal);
    border-width: 0;
    overflow-x: hidden;
    --btn-active-shadow: none;
    --btn-height: var(--note-emoji-size);
}

.note-emoji-skin {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background-color: var(--c, #ffdc5d);
    transition: transform 0.12s;

    &.active {
        outline: 2px solid rgba(0,0,0, 0.6);
        transition: none;
    }

    &:hover:not(.active) {
        transform: scale(1.35);
    }
}


// Misc
// -----------------------

.note-fontsize-10 {
    font-size: 10px;
}

.note-current-fontsize {
    // Fix: the current font button width should not change (toolbar flickers)
    display: inline-block;
    width: 16px;
}

.note-para > .btn-group:last-child .dropdown-menu.show {
    // Fix: the para popover button groups should not wrap
    display: flex !important;
}

.note-font > .btn-group:first-child > .btn {
    // Fix: the fontsize button width should not change (toolbar flickers)
    padding-inline: 0.5rem;
    width: 112px;
    max-width: 112px;
    justify-content: space-between;
    font-weight: 400;

    > .note-current-fontname {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
}

.note-dropdown-menu {
    &.dropdown-fontsize {
        min-width: 92px;
    }

    &.dropdown-cssclass > .dropdown-item {
        position: relative;

        > .d-block {
            width: 100%;
        }

        &.checked {
            order: -1;

            &:before {
                position: absolute;
                content: '';
                inset-inline-start: 0;
                top: 0;
                bottom: 0;
                width: 3px;
                background-color: var(--warning);
            }
        }
    }
}

// Horizontal resize handle
.note-hresize-handle {
    position: absolute;
    // top/left/height set dynamically to follow .note-editable
    width: 5px;
    cursor: col-resize;
    background: rgba($black, .1);
    background: $note-bg;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: center;

    &:hover {
        background: rgba($black, .12);
    }

    &:before,
    &:after {
        content: '';
        position: absolute;
        top: 50%;
        width: 1px;
        height: 20px;
        transform: translate(0, -50%);
        background: rgba($black, 0.2);
        pointer-events: none;
    }

    &:before {
        left: 1px;
    }

    &:after {
        left: 3px;
    }
}

// Cursor and selection state during resize
.note-editor.resizing {
    user-select: none;
}
